<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>鼠标在盒子中的位置</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        margin-left: 500px;
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <script>
      var box = document.querySelector(".box");
      box.addEventListener("click", function (e) {
        console.log(e.clientX - this.offsetLeft);
        console.log(e.clientY - this.offsetTop);
      });
    </script>
  </body>
</html>
